﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using XLua;
[LuaCallCSharp]
public class TransformLua
{
    public static Transform m_transform;

    public static void On(uint skinID)
    {
        GameObject go = ObjectManager.Instance.GetGameObject(skinID);
        if (go != null)
        {
            m_transform = go.transform;
        }
    }

    public static void Off()
    {
        m_transform = null;
    }

    public static void SetPos(uint skinID, float x, float y, float z, bool isLocal = true)
    {
        On(skinID);
        SetPos(x, y, z, isLocal);
    }


    public static void SetPos(float x, float y, float z, bool isLocal = true)
    {
        if (m_transform == null) return;
        if (isLocal)
        {
            m_transform.localPosition = new Vector3(x, y, z);
        }
        else
        {
            m_transform.position = new Vector3(x, y, z);
        }
    }


    public static void SetPosX(uint skinID, float x, bool isLocal = true)
    {
        On(skinID);
        SetPosX(x, isLocal);
    }

    public static void SetPosX(float x, bool isLocal = true)
    {
        if (m_transform == null) return;
        float y = 0, z = 0;
        if (isLocal)
        {
            Vector3 pos = m_transform.localPosition;
            y = pos.y;
            z = pos.z;
        }
        else
        {
            Vector3 pos = m_transform.position;
            y = pos.y;
            z = pos.z;
        }
        SetPos(x, y, z, isLocal);
    }

    public static void SetPosY(uint skinID, float y, bool isLocal = true)
    {
        On(skinID);
        SetPosY(y, isLocal);
    }

    public static void SetPosY(float y, bool isLocal = true)
    {
        if (m_transform == null) return;
        float x = 0;
        float z = 0;
        if (isLocal)
        {
            Vector3 pos = m_transform.localPosition;
            x = pos.x;
            z = pos.z;
        }
        else
        {
            Vector3 pos = m_transform.position;
            x = pos.x;
            z = pos.z;
        }
        SetPos(x, y, z, isLocal);
    }

    public static void SetPosZ(uint skinID, float z, bool isLocal = true)
    {
        On(skinID);
        SetPosZ(z, isLocal);
    }

    public static void SetPosZ(float z, bool isLocal = true)
    {
        if (m_transform == null) return;
        float x = 0;
        float y = 0;
        if (isLocal)
        {
            Vector3 pos = m_transform.localPosition;
            x = pos.x;
            y = pos.y;
        }
        else
        {
            Vector3 pos = m_transform.position;
            x = pos.x;
            y = pos.y;
        }
        SetPos(x, y, z, isLocal);
    }

    public static void SetParent(uint skinID, string path)
    {
        On(skinID);

        //SetParent()
    }


    public static void SetParent(uint skinID, uint parentID)
    {
        On(skinID);
        GameObject go = ObjectManager.Instance.GetGameObject(parentID);
        if (go != null)
        {
            SetParent(go.transform);
        }
    }


    public static void SetParent(Transform tran)
    {
        if (m_transform == null) return;
        m_transform.SetParent(tran);
    }

    public static void SetActive(uint skinID, bool isActive)
    {
        On(skinID);
        SetActive(isActive);
    }

    public static void SetActive(bool isActive)
    {
        if (m_transform == null) return;
        m_transform.gameObject.SetActive(isActive);
    }
}

